import unittest

from selenium.webdriver.common.by import By

import TEST1


class Test1(unittest.TestCase):
    def setUp(self):
        # 可选：在每个测试方法前执行初始化操作
        self.userName = '2969476744'
        self.passWord = '123456'
        self.admin_userName = 'admin'
        self.admin_password = '123456'
        self.UserInfo = {
            'username': '1228912646',
            'password': '123456',
            'realname': '朱弘光',
            'phone': '15081349872',
            'email': '1228912646@qq.com'
        }

    def test_admin_add_user(self):
        TEST1.admin_add_user(self.admin_userName, self.admin_password, self.UserInfo)
        # 可添加断言检查用户是否添加成功
        data = TEST1.query("SELECT * FROM user WHERE username = '{}'".format(self.UserInfo['username']))
        self.assertEqual(len(data), 1)

    def test_login(self):
        driver = TEST1.login(self.userName, self.passWord)
        brand_text = driver.find_element(By.CLASS_NAME, "navbar-brand").text
        self.assertIn(brand_text, ["个人理财系统", "后台管理系统"])

    def test_register(self):
        TEST1.register(self.userName, self.passWord)
        data = TEST1.query("SELECT * FROM user WHERE username = '{}'".format(self.userName))
        self.assertEqual(len(data), 1)

    def test_admin_Delete(self):
        TEST1.admin_Delete(self.admin_userName, self.admin_password)
        # 可添加断言验证删除后数据库状态或页面元素变化
        pass  # 根据实际逻辑补充断言


if __name__ == '__main__':
    unittest.main()
